#ifndef CLASS_COMPOSITE_GOAL
#define CLASS_COMPOSITE_GOAL

#include <list>
#include "goal.h"

namespace spsu_art {

class composite_goal : public goal {
private:

    std::list<goal*> subgoals;

protected:
    /*!@brief Activates and calls each subgoal in turn
     *
     * @return The status of the subgoals
     *
     * This does all the actual work of calling the topmost
     * subgoal. It also handles the deletion of finshed or failed
     * subgoals.
     */ 
    g_status process_subgoals();

    /*!@brief Removes all subgoals from this object's list.
     *
     * @return nothing
     *
     * This should be called to destroy all functions on the list.
     * It calls each subgoal's terminate member to allow the function
     * to clean up before it is deleted.
     */
    void remove_subgoals();

    /*!@brief Adds a subgoal to the end of the list to be processed.
     *
     * @return nothing
     * @param subgoal A pointer to the subgoal to be added to the list
     *
     * Used to script events. Goals will be evaluated in the same order
     * they were placed in the list. This is used as the main general
     * way to put goals on the list.
     */ 
    void add_subgoal(goal* subgoal);

    /*!@brief Pushes a subgoal on the front of the list.
     *
     * @return nothing
     * @param subgoal A pointer to the subgoal to be placed on the stack
     *
     * Used to handle sudden events. A goal capable of handling
     * the event is pushed onto the top of the stack. It 
     * subsequently becomes the current goal. If it succeeds the
     * goal that was pushed down simply resumes it's mission or 
     * replans if it needs to.
     */
    void push_subgoal(goal* subgoal);

    //!@brief Returns wheather this is a composite goal or not
    bool static is_composite();

public:

    /*!@brief Sends messages further down the hierarcy before handing
     * it to this goal.
     *
     * @return Wheather or not the message was handled
     * @param message The message to be handled
     */
    bool forward_message(const telegram& message);
} //end class composite_goal

} //end namespace spsu_art

#endif
